package com.devicemantra.coordinate.dataobjects;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.*;


import java.text.SimpleDateFormat;
import java.util.*;

import com.devicemantra.coordinate.ds.tests.PMF;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class CronObj 
{
	@PrimaryKey
    @Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key mMessageKey;
	
	@Persistent
	private Date mDate;
	
	
	
	public CronObj()
	{
		mDate = new Date();
		mDate = getDateInTimeZone(mDate, "Asia/Dubai");
		System.out.println("Date is " + mDate);
	}
	
	public  Date getDateInTimeZone(Date currentDate, String timeZoneId)
	{
	TimeZone tz = TimeZone.getTimeZone(timeZoneId);
	Calendar mbCal = new GregorianCalendar(TimeZone.getTimeZone(timeZoneId));
	mbCal.setTimeInMillis(currentDate.getTime());

	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.YEAR, mbCal.get(Calendar.YEAR));
	cal.set(Calendar.MONTH, mbCal.get(Calendar.MONTH));
	cal.set(Calendar.DAY_OF_MONTH, mbCal.get(Calendar.DAY_OF_MONTH));
	cal.set(Calendar.HOUR_OF_DAY, mbCal.get(Calendar.HOUR_OF_DAY));
	cal.set(Calendar.MINUTE, mbCal.get(Calendar.MINUTE));
	cal.set(Calendar.SECOND, mbCal.get(Calendar.SECOND));
	cal.set(Calendar.MILLISECOND, mbCal.get(Calendar.MILLISECOND));

	return cal.getTime();
	}
	
}
